<!DOCTYPE html>
<html lang="en">
<head>
    <include file="Public/public_head" title="添加学校-"/>
    <css file="__PUBLIC__/static/ueditor1_4_3/third-party/SyntaxHighlighter/shCoreDefault.css"/>

<script>


    function showPosition(position)    {

        lnglat=position.coords.longitude.toFixed(6)+','+position.coords.latitude.toFixed(6);


         var url= "/Home/index/add/lnglat/"+lnglat;

         window.location.href = url;



    }

    function showError(error)
    {
        switch(error.code)
        {
            case error.PERMISSION_DENIED:
                alert("请允许浏览器获取地理位置！");
                break;
            case error.POSITION_UNAVAILABLE:
                alert("Location information is unavailable.");
                break;
            case error.TIMEOUT:
                alert("The request to get user location timed out.");
                break;
            case error.UNKNOWN_ERROR:
                alert("An unknown error occurred.");
                break;
        }
    }


    function getLocation(){



        if (navigator.geolocation){

            navigator.geolocation.getCurrentPosition(showPosition,showError);


        }
        else{
            window.location.href="{:U('Home/index/add',array('lnglat'=>'116.405467,39.907761'))}";
        }
    }
</script>

</head>
<body>
<include file="Public/public_nav"/>
<div class="b-h-70"></div>

<empty name="lnglat">
    <script>

        window.onload=getLocation;
    </script>
<else/>


    <div class="container">
        <div class="row">
            <div class="col-md-9 col-lg-push-1 main-content">
                <div class="panel">
                    <div class="panel-heading">
                        <h3>添加学校</h3>
                    </div>
                    <div class="panel-body">
                <form  id="school-add" name="form1" action="" class="form-horizontal"  method="post"    target="_blank" >

                    <div class="form-group">
                          <div class="col-md-6"><input class="form-control" type="text" id="title" name="title" placeholder="校名"></div>
                          <div class="col-md-3">
                              <select id="beginyear" name="beginyear" class="form-control">
                                  <option value=''>建校年份</option>
                                  <?php for ($x=date('Y'); $x>=date('Y')-80; $x--){ ?>
                                  <option value='{$x}'>{$x}</option>
                                  <?php } ?>
                              </select>
                          </div>
                          <div class="col-md-3">


                                  <div class="inputword" style="height:40px;padding-top:6px">
                                      已注册
                                      <input type="checkbox" class="icheck" id="verify" name="verify"   value='1'>
                                  </div>


                          </div>
                    </div>


                    <div class="form-group">
                        <div class="col-md-12">
                            <div class="inputword" style="height:40px;padding-top:6px">
                                <foreach name="allTag" item="v">
                                    <span >{$v['tname']}</span>
                                    <input class="icheck"  type="checkbox" id="tids[]" name="tids[]" value="{$v['tid']}"> &emsp;
                                </foreach>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-4"><select name="province" id="province"  class="form-control"></select></div>
                        <div class="col-md-4"> <select name="city"  id="city"  class="form-control"></select></div>
                        <div class="col-md-4"> <select name="area"  id="area"  class="form-control" ></select></div>
                        <script type="text/javascript">new PCAS("province={$location.province},请选择省份","city={$location.city},请选择城市","area={$location.area},请选择地区");</script>
                    </div>
                    <div class="form-group">
                        <div class="col-md-4"> <input type="text" id="address" name="address" class="form-control"  placeholder="具体地址"  tooltipText="具体地址" ></div>

                        <div class="col-md-4">
                            <input type="text" id="lnglat" name="lnglat"  class="form-control"  placeholder="经纬度，请点击地图获取" tooltipText="经纬度，请点击地图获取">
                        </div>
                        <div class="col-md-4">
                            <input type="text" id="acreage" name="acreage" class="form-control"  placeholder="占地面积">
                        </div>

                    </div>
                    <div class="form-group">
                        <div class="col-md-12">
                            <div  id="iCenter" style="width:100%;height:450px"></div>
                        </div>
                    </div>
                    <div class="form-group">

                        <div class="col-md-11">
                            <input type="text" id="key_1" value="" class="form-control" placeholder="请输入地名关键词查询" />

                        </div><div class="col-md-1"><a href="javascript:;"  onclick="placeSearch()"><i class="fa fa-search"></i> </a></div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            <select name="teacher" id="teacher"  class="form-control">
                                <option value=''>教师人数</option>
                                <volist name='option.teacher_option' id='v' key="k">
                                    <option value='{$k}'>{$v}</option>
                                </volist>
                            </select>
                        </div>

                        <div class="col-md-3">
                            <select name="salary" id="salary"  class="form-control">
                                <option value=''>薪资水平</option>
                                <volist name='option.salary_option' id='v' key="k">
                                    <option value='{$k}'>{$v}</option>
                                </volist>
                            </select>
                        </div>

                        <div class="col-md-3">
                            <select name="student" id="student"  class="form-control">
                                <option value=''>学生人数</option>
                                <volist name='option.student_option' id='v' key="k">
                                    <option value='{$k}'>{$v}</option>
                                </volist>
                            </select>
                        </div>

                        <div class="col-md-3">
                            <select name="price" id="price"  class="form-control">
                                <option value=''>学费水平</option>
                                <volist name='option.price_option' id='v' key="k">
                                    <option value='{$k}'>{$v}</option>
                                </volist>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-12">
                            <div>
                                <script type="text/plain" id="editor" name='content' style="width:100%;height:50px;"></script>
                            </div>
                        </div>
                    </div>


                    <div id='feedbox'>

                            <div class="form-group">

                                <div class="col-md-2">
                                    <input type="text" name="c_name[]" class="form-control" value="" placeholder="姓名">
                                </div>
                                <div class="col-md-2">
                                        <select name="role[]"  class="form-control">
                                            <option value=''>职位</option>
                                            <volist name='option.role_option' id='v' key="k">
                                                <option value='{$k}'>{$v}</option>
                                            </volist>
                                        </select>

                                </div>
                                <div class="col-md-2">
                                    <input type="text" name="tel[]" class="form-control" value="" placeholder="手机">
                                </div>
                                <div class="col-md-2">
                                    <input type="text" name="email[]" class="form-control" value="" placeholder="邮箱">
                                </div>
                                <div class="col-md-2">
                                    <input type="text" name="wechat[]" class="form-control" value="" placeholder="微信">
                                </div>
                                <div class="col-md-2">


                                    <i class="fa fa-minus" onclick="$(this).parent().parent().remove();return false;"></i>&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="javascript:;"  id = "add" ><i class="fa fa-plus"></i></a>
                                </div>
                            </div>



                    </div>


                    <div class="form-group">
                        <div class="col-md-12">
                            <div class="inputword" style="height:40px;padding-top:6px">
                                <span class="inputword">直接发布</span> <input class="icheck" type="radio" name="is_show" value="1"
                                                                        checked="checked"> &emsp; <span class="inputword">存为草稿</span>
                                <input class="icheck" type="radio" name="is_show" value="0">
                            </div>
                            </div>
                    </div>
                    <div class="form-group">
                            <div class="col-md-12"><input class="btn btn-success" type="submit" value="添加"></div>
                        </div>

                </form>
                        </div>

                </div>
            </div>
        </div>
    </div>



<include file="Public/public_login"/>
<include file="Public/public_foot"/>
<js file="__PUBLIC__/static/ueditor1_4_3/third-party/SyntaxHighlighter/shCore.js"/>
<js file="__PUBLIC__/static/layer-2.4/layer.js"/>
<script src="__PUBLIC__/static/ueditor1_4_3/ueditor.config.js"></script>
<script src="__PUBLIC__/static/ueditor1_4_3/ueditor.all.js"></script>
<link href="__PUBLIC__/static/ueditor1_4_3/themes/default/css/ueditor.css" type="text/css" rel="stylesheet">
<script>
    var mapObj;
    var lnglatXY;
    var geolocation;
    var result;
    //初始化地图
    /* function mapInit(){


        var opt = {
            level: 10, //设置地图缩放级别
            center: new AMap.LngLat({$lnglat}) //设置地图中心点
        }
        mapObj = new AMap.Map("iMap", opt);

        AMap.event.addListener(mapObj,'click',getLnglat); //点击事件

        addMarker()
    }*/
    function geocoder() {

        var MGeocoder;
        //加载地理编码插件
        mapObj.plugin(["AMap.Geocoder"], function() {
            MGeocoder = new AMap.Geocoder({
                radius: 1000,
                extensions: "all"
            });
            //返回地理编码结果
            AMap.event.addListener(MGeocoder, "complete", geocoder_CallBack);
            //逆地理编码
            MGeocoder.getAddress(lnglatXY);
        });
        //加点
        var marker = new AMap.Marker({
            map:mapObj,
            icon:"http://webapi.amap.com/images/0.png",
            position: lnglatXY,
            offset: new AMap.Pixel(-5,-30)
        });
        // mapObj.setFitView();
    }
    //回调函数
    function geocoder_CallBack(data) {
        var address;
        //返回地址描述
        address = data.regeocode.formattedAddress;
        //返回结果拼接输出
        //document.getElementById("iAddress").innerHTML = address;
    }
    //鼠标点击，获取经纬度坐标
    function getLnglat(e){
        mapObj.clearMap();
        var x = e.lnglat.getLng();
        var y = e.lnglat.getLat();
        document.getElementById("lnglat").value = x + "," + y;

        lnglatXY = new AMap.LngLat(x,y);
        geocoder();
    }

    //实例化marker
    function addMarker(){
        marker=new AMap.Marker({
            icon:"http://webapi.amap.com/images/0.png",
            position:new AMap.LngLat({$lnglat}),
        });

        marker.setMap(mapObj);  //在地图上添加点
    }

    function addMarker2(){
        mapObj.clearMap();
        marker2 = new AMap.Marker({
            position:(new AMap.LngLat({$lnglat})),
            draggable:true,  //点标记可拖拽
            cursor:'move',
            raiseOnDrag:true //鼠标拖拽点标记时开启点标记离开地图的效果
        });
        marker2.setMap(mapObj);
    }
    function marker2Cartoon(){
        marker2.setAnimation('AMAP_ANIMATION_BOUNCE'); //设置点标记的动画效果，此处为弹跳效果
    }
    function mapInit () {
        mapObj = new AMap.Map('iCenter');    //默认定位：初始化加载地图时，center及level属性缺省，地图默认显示用户所在城市范围
        AMap.event.addListener(mapObj,'click',getLnglat); //点击事件
    };
    function getCurrentPosition () { //调用浏览器定位服务
        mapObj.plugin('AMap.Geolocation', function () {
            geolocation = new AMap.Geolocation({
                enableHighAccuracy: true,//是否使用高精度定位，默认:true
                timeout: 10000,          //超过10秒后停止定位，默认：无穷大
                maximumAge: 0,           //定位结果缓存0毫秒，默认：0
                convert: true,           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
                showButton: true,        //显示定位按钮，默认：true
                buttonPosition: 'LB',    //定位按钮停靠位置，默认：'LB'，左下角
                buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                showMarker: true,        //定位成功后在定位到的位置显示点标记，默认：true
                showCircle: true,        //定位成功后用圆圈表示定位精度范围，默认：true
                panToLocation: true,     //定位成功后将定位到的位置作为地图中心点，默认：true
                zoomToAccuracy:true      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            });
            mapObj.addControl(geolocation);
            AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
            AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
        });
    };
    function onComplete (data) {   //解析定位结果
        var str = '<p>定位成功</p>';
        str += '<p>经度：' + data.position.getLng() + '</p>';
        str += '<p>纬度：' + data.position.getLat() + '</p>';
        str += '<p>精度：' + data.accuracy + ' 米</p>';
        str += '<p>是否经过偏移：' + (data.isConverted ? '是' : '否') + '</p>';
        result.innerHTML = str;
    };
    function onError (data) {    //解析定位错误信息
        var str = '<p>定位失败</p>';
        str += '<p>错误信息：'
        switch(data.info) {
            case 'PERMISSION_DENIED':
                str += '浏览器阻止了定位操作';
                break;
            case 'POSITION_UNAVAILBLE':
                str += '无法获得当前位置';
                break;
            case 'TIMEOUT':
                str += '定位超时';
                break;
            default:
                str += '未知错误';
                break;
        }
        str += '</p>';
        result.innerHTML = str;
    };
    function showCityInfo() {  //IP定位
        //加载IP定位插件
        mapObj.plugin(["AMap.CitySearch"], function() {
            //实例化城市查询类
            var citysearch = new AMap.CitySearch();
            //自动获取用户IP，返回当前城市
            citysearch.getLocalCity();
            AMap.event.addListener(citysearch, "complete", function(result){
                if(result && result.city && result.bounds) {
                    var cityinfo = result.city;
                    var citybounds = result.bounds;
                    document.getElementById('result').innerHTML = "您当前所在城市："+cityinfo+"";
                    //地图显示当前城市
                    mapObj.setBounds(citybounds);
                }
                else {
                    document.getElementById('result').innerHTML = "您当前所在城市："+result.info+"";
                }
            });
            AMap.event.addListener(citysearch, "error", function(result){alert(result.info);});
        });
    }
    var MSearch;
    var key_1;
    function placeSearch() {  //POI搜索，关键字查询
        key_1 = document.getElementById("key_1").value;
        mapObj.plugin(["AMap.PlaceSearch"], function() {    //构造地点查询类
            MSearch = new AMap.PlaceSearch({
                pageSize:10,
                pageIndex:1,
                city:"all" //城市
            });
            AMap.event.addListener(MSearch, "complete", function(data){
                var poiArr = data.poiList.pois;
                var lngX = poiArr[0].location.getLng();
                var latY = poiArr[0].location.getLat();
                mapObj.setCenter(new AMap.LngLat(lngX, latY));
                geocoder();
            });//返回地点查询结果
            MSearch.search(key_1); //关键字查询
        });
    }


    var ue = UE.getEditor('editor',{
        toolbars: [['bold','italic','underline','justifyleft','justifycenter','justifyright','link','inserttable','simpleupload','insertimage','insertvideo','source']],
        autoClearinitialContent: true,
        wordCount: false,
        elementPathEnabled: false,
        initialContent: "请至少上传两张照片"
    });


$(function(){

    $('#school-add').on('submit', function(e) {
        e.preventDefault();


        var title = $.trim($('#title').val());
        var beginyear = $.trim($('#beginyear').val());
        var verify=getCheckboxValue('verify');
        var tids=getCheckboxValue('tids[]');
        var province = $('#province ').val();
        var city = $('#city').val();
        var area = $('#area').val();
        var address = $.trim($('#address').val());
        var lnglat = $.trim($('#lnglat').val());
        var acreage = $.trim($('#acreage').val());
        var student = $.trim($('#student').val());
        var price = $.trim($('#price').val());
        var teacher = $.trim($('#teacher').val());
        var salary = $.trim($('#salary').val());
        var content = UE.getEditor('editor').getPlainTxt();




        if (title == '') {
            bootbox.alert('学校名称不能为空！');
            return false;
        }
        if (tids == '') {
            bootbox.alert('标签不能为空！');
            return false;
        }

        if (address == '') {
            bootbox.alert('具体地址不能为空！');
            return false;
        }
        if (lnglat == '') {
            bootbox.alert('请点击地图确定学校的位置！');
            return false;
        }


        if (acreage == '') {
            bootbox.alert('面积不能为空！');
            return false;
        }

        if (acreage < 0){
            bootbox.alert('面积不能为负数！');
            return false;
        }

        if (teacher == '') {
            bootbox.alert('教师人数不能为空！');
            return false;
        }


        if (salary == '') {
            bootbox.alert('月薪水平不能为空！');
            return false;
        }


        if (student == '') {
            bootbox.alert('学生人数不能为空！');
            return false;
        }


        if (price == '') {
            bootbox.alert('学费水平不能为空！');
            return false;
        }

        if (content == '') {
            bootbox.alert('学校描述不能为空！');
            return false;
        }


        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{:U('home/index/add')}",
            data: $("#school-add").serialize(),
            success: function(data){
                if (data.status == 0) {
                    bootbox.alert(data.info);
                    return  false;
                } else {
                    window.location.href = data.url;
                }

            }
        });
    });

});



    $("#add").click(function(){

        var div = '<div class="form-group">';
        div=div+'<div class="col-md-2"><input type="text" name="c_name[]" class="form-control" placeholder="姓名"></div>';
        div=div+'<div class="col-md-2"> <select name="role[]"  class="form-control"><option value="">职位</option><volist name="option.role_option" id="v" key="k"><option value="{$k}">{$v}</option></volist></select></div>';
        div=div+'<div class="col-md-2"><input type="text" name="tel[]" class="form-control" placeholder="手机"></div>';
        div=div+'<div class="col-md-2"><input type="text" name="email[]" class="form-control" placeholder="邮箱"></div>';
        div=div+'<div class="col-md-2"><input type="text" name="wechat[]" class="form-control" placeholder="微信"></div>';
        div=div+'<div class="col-md-2"><i class="fa fa-minus" onclick="$(this).parent().parent().remove();return false;"></i></div></div>';

        $("#feedbox").append(div);//向form中追加div
        j+=1;
    });

    $("#del").click(function(){
        $(this).parent().parent().remove();
    });

</script>

</empty>
<script>
    window.onload=mapInit;
</script>
</body>
</html>